
#ifndef MEMORY_H
#define MEMORY_H
	
	#define MEMORY_PAGE_SIZE 4096  //页长
	#define MEMORY_FREE_SUB_SIZE 4000 //空闲区的表长度
	#define MEMORY_MANAGE_ADDR	0x003c0000 //我们把内存管理表放在这个位置
	#define MEMORY_START 0x400000
	typedef struct  {
		unsigned addr ,size ;
	} MEMORY_SUB; //memory subarea 

	typedef struct  { 
		unsigned int totalsize ;
		int frees , maxfrees ,lostsize ,losts ;
		MEMORY_SUB freem[MEMORY_FREE_SUB_SIZE] ;
	} MEMORY_MANAGEMENT; //memory management 


	unsigned int  memtest (unsigned int start ,unsigned int end );
	void memman_init (MEMORY_MANAGEMENT *man) ;
	unsigned int memman_alloc (MEMORY_MANAGEMENT * man ,unsigned int size );
	unsigned int memman_free_total (MEMORY_MANAGEMENT * man) ;
	int memman_free (MEMORY_MANAGEMENT * man ,unsigned int addr ,unsigned int size );

	unsigned int memman_alloc_4k (MEMORY_MANAGEMENT * man ,unsigned int size ) ;
	int memman_free_4k (MEMORY_MANAGEMENT * man ,unsigned int addr ,unsigned int size ) ;
#endif 
	  
